<?php

include './Config.class.php';

class MySQL {
    
    private $objConfig;
    
    private $host;
    private $user;
    private $pass;
    private $bd;
        
    var $query;
    var $link;
    var $result;
    
    function MySQL(){
        $this->objConfig = new Config();
        
        $this->host = $this->objConfig->getCaminhoBanco();
        $this->user = $this->objConfig->getUserBanco();
        $this->pass = $this->objConfig->getSenhaBanco();
        $this->bd = $this->objConfig->getNomeBanco();
        
    }
		
    function connect(){
        $this->link = mysql_connect($this->host,$this->user,$this->pass);
        if(!$this->link){
            echo "Erro na Conexão.<br>"
            ."<b>MySQL retornou: </b> ".mysql_error()."<br>";
            die();
            
        }elseif (!mysql_select_db($this->db,$this->link)){
            echo "Erro na seleção do Banco de Dados.<br>"
            ."<b>MySQL retornou: </b> ".mysql_error()."<br>";
            die();
        }    
    }


    function sql($query){
        $this->connect();
        $this->query = $query;
        if($this->result === mysql_query($this->query)){
            $this->disconnect();
            return $this->result;
            
        }else{
            die("Ocorreu um erro ao executar a Query SQL abaixo:<br>$query<<br><br><b>MySQL Retornou: ".  \mysql_error()."<b>");
            $this->disconnect();
            
        }    
    }
          
    function disconnect(){
        return mysql_close($this->link);
    }
}
